﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
namespace TuongLai_Schools
{
    public class cls_DM_Diemdanhgia
    {
        public DataTable GetAll_Diemdanhgia(int caphocid)
        {
            DbAccess db = new DbAccess();
            db.CreateNewSqlCommand_Text();
            DataTable dataTable = db.ExecuteDataTable("Select DiemDanhGiaID,TenDiemDanhGia,GhiChu,FK_CapHocID,isChangeable from DM_DiemDanhGia where FK_CapHocID=" + caphocid + "");
            return dataTable;
        }
        public DataTable GetAll_Caphoc()
        {
            DbAccess db = new DbAccess();
            db.CreateNewSqlCommand_Text();
            DataTable dataTable = db.ExecuteDataTable("Select ROW_NUMBER() OVER(ORDER BY TenCapHoc) as TT, CapHocID,TenCapHoc from DM_CapHoc");
            return dataTable;
        }
        public bool Insert(clsDM_Diemdanhgia obj)
        {
            try
            {
                DbAccess db = new DbAccess();
                db.CreateNewSqlCommand_Text();
                db.AddParameter("@DiemDanhGiaID", obj.DiemĐanhGiaID);
                db.AddParameter("@TenDiemDanhGia", obj.TenDiemDanhGia);
                db.AddParameter("@GhiChu", obj.GhiChu);
                db.AddParameter("@FK_CapHocID", obj.FK_CapHocID);
                db.AddParameter("@isChangeable", obj.isChangeable);
                db.ExecuteNonQuery("insert into DM_DiemDanhGia(TenDiemDanhGia,GhiChu,FK_CapHocID,isChangeable) values(N'" + obj.TenDiemDanhGia + "',N'" + obj.GhiChu + "',"+ obj.FK_CapHocID +",'" + obj.isChangeable + "')");
                return true;
            }
            catch
            {
                return false;
            }
        }
        public bool update(clsDM_Diemdanhgia obj)
        {
            try
            {
                DbAccess db = new DbAccess();
                db.CreateNewSqlCommand_Text();
                db.AddParameter("@DiemDanhGiaID", obj.DiemĐanhGiaID);
                db.AddParameter("@TenDiemDanhGia", obj.TenDiemDanhGia);
                db.AddParameter("@GhiChu", obj.GhiChu);
                db.AddParameter("@FK_CapHocID", obj.FK_CapHocID);
                db.AddParameter("@isChangeable", obj.isChangeable);
                db.ExecuteNonQuery("update DM_DiemDanhGia set TenDiemDanhGia=N'" + obj.TenDiemDanhGia + "',GhiChu=N'" + obj.GhiChu + "',isChangeable='" + obj.isChangeable + "' where DiemDanhGiaID='" + obj.DiemĐanhGiaID + "'");
                return true;
            }
            catch
            {
                return false;
            }
        }
        public bool delete(int Diemdanhgiaid)
        {
            try
            {
                DbAccess db = new DbAccess();
                db.CreateNewSqlCommand_Text();
                db.AddParameter("@DiemDanhGiaID", Diemdanhgiaid);
                db.ExecuteNonQuery("delete DM_DiemDanhGia where DiemDanhGiaID=" + Diemdanhgiaid + "");
                return true;
            }
            catch
            {
                return false;
            }
        }
    }
}
